package com.gxa.service.score.impl;

import com.gxa.common.R.ResponseData;
import com.gxa.mapper.score.ScoreMapper;
import com.gxa.pojo.Score;
import com.gxa.service.score.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ScoreServiceImpl implements ScoreService {

    @Autowired
    private ScoreMapper scoreMapper;

    @Transactional(rollbackFor = Throwable.class)
    @Override
    public ResponseData system(Integer currentPage, Integer pageSize) {
            ResponseData r = new ResponseData();
            currentPage = (currentPage - 1) * pageSize + 1;
            pageSize = currentPage + pageSize - 1;
            List<Score> list= scoreMapper.system(currentPage, pageSize);
            if (list != null) {
                System.out.println("进入成功");
                r.setCode(200);
                r.setMsg("success");
                r.setData(list);
            }
            return r;
    }

    @Transactional(rollbackFor = Throwable.class)
    @Override
    public ResponseData scoreIn(Integer id) {
        ResponseData r = new ResponseData();
        Score score = scoreMapper.scoreIn(id);
        if (score != null) {
            System.out.println("进入成功");
            r.setCode(200);
            r.setMsg("success");
            r.setData(score);
        }
        return r;
    }

    @Transactional(rollbackFor = Throwable.class)
    @Override
    public ResponseData addScore(Score score) {
        ResponseData r = new ResponseData();
        int result = scoreMapper.addScore(score);
        if (result > 0) {
            System.out.println("添加成功");
            r.setCode(200);
            r.setMsg("success");
            r.setData(result);
        }
        return r;
    }

    @Transactional(rollbackFor = Throwable.class)
    @Override
    public ResponseData addScore2(Score score) {
        ResponseData r = new ResponseData();
        int result = scoreMapper.addScore2(score);
        if (result > 0) {
            System.out.println("添加成功");
            r.setCode(200);
            r.setMsg("success");
            r.setData(result);
        }
        return r;
    }

    @Transactional(rollbackFor = Throwable.class)
    @Override
    public ResponseData selectScore(String selectMsg, String keyWord, Integer currentPage, Integer pageSize) {
        ResponseData r = new ResponseData();
        currentPage = (currentPage - 1) * pageSize + 1;
        pageSize = currentPage + pageSize - 1;
        List<Score> list = scoreMapper.selectScore(selectMsg, keyWord, currentPage, pageSize);
        if (list != null) {
            System.out.println("查找成功");
            r.setCode(200);
            r.setMsg("success");
            r.setData(list);
        }
        return r;
    }

    @Transactional(rollbackFor = Throwable.class)
    @Override
    public ResponseData record(Integer currentPage, Integer pageSize) {
        ResponseData r = new ResponseData();
        currentPage = (currentPage - 1) * pageSize + 1;
        pageSize = currentPage + pageSize - 1;
        List<Score> list= scoreMapper.record(currentPage, pageSize);
        if (list != null) {
            System.out.println("进入成功");
            r.setCode(200);
            r.setMsg("success");
            r.setData(list);
        }
        return r;
    }

    @Transactional(rollbackFor = Throwable.class)
    @Override
    public ResponseData selectRecord(String keyWord, Integer currentPage, Integer pageSize) {
        ResponseData r = new ResponseData();
        currentPage = (currentPage - 1) * pageSize + 1;
        pageSize = currentPage + pageSize - 1;
        List<Score> list = scoreMapper.selectRecord(keyWord, currentPage, pageSize);
        if (list != null) {
            System.out.println("查找成功");
            r.setCode(200);
            r.setMsg("success");
            r.setData(list);
        }
        return r;
    }

}
